<?php
//Lay so dong tren mot danh sach
$v_num = '';
$v_dem = -1;
$v_limit_row = _CONST_NUMBER_OF_ROW_PER_LIST;
if(isset($_REQUEST['hdn_record_number_page'])){
	$v_limit_row = $_REQUEST['hdn_record_number_page'];
}

//Lay trang thu x
$v_page = 1;
if(isset($_REQUEST['hdn_page'])){
	$v_page=$_REQUEST['hdn_page'];	
}
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
$v_staff_id = $_SESSION['staff_id'];
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = "";
}
$v_display_type = onegate_is_approve_leader_type($_SESSION['staff_id'], $_SESSION['onegate_current_recordtype'], $_SESSION["recordtype"]);
//echo $v_display_type;exit;
$arr_leader = get_all_leader_convert_arr($v_recordtype_filter,$_SESSION['recordtype']);

$v_display = "none";
if ($v_count_worktype > 0){
	$v_display = "block";
}

$v_file_url = trim(CONST_URL_PATH_FROM_ROOT) . $v_file_name;
$v_goto_url = "javascript:filename_onclick('T_ONEGATE_RECORD_WORK', 'PK_RECORD_WORK', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_record_work_id) . ",'" . $v_file_url ."');" ;
// xac dinh label hien thi: trinh ky, duoc giai quyet, khong duoc giai quyet
$arr_result_label = onegate_get_label_of_result_type($_SESSION['recordtype'],$v_recordtype_filter);
//var_dump($arr_result_label);exit;
$v_work_date = date("d/m/Y");
?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="large_title">
		<td><?php echo CONST_RECORD_APPROVING_UPDATE_TITLE; ?></td>
	</tr>
</table>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" cellpadding="0" cellspacing="0" border="0">
	<col width="20%"><col width="80%">
	<tr>
		<form action="index.php" method="post" name="f" enctype= "multipart/form-data">
		<input type="hidden" name="fuseaction" value="" >
		<input type="hidden" name="fuseaction_back" value="<?php echo $fuseaction_back; ?>">
		<input type="hidden" name="hdn_record_id"  value="<?php echo $v_record_id; ?>">
		<input type="hidden" name="hdn_record_id_list"  value="<?php echo $v_record_id_list; ?>">	<!--nieuvv--120808--->
		<input type="hidden" name="hdn_fisrt" value="">
		<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
		<input type="hidden" name="hdn_work" value="">
		<input type="hidden" name="hdn_revoke" value="false">
		<input type='hidden' name='hdn_page' value='<?php echo $v_page;?>'>
		<input type='hidden' name='hdn_record_number_page' value='<?php echo $v_limit_row;?>'>
	</tr>
	<tr>
		<td colspan="10"><?php echo onegate_show_record_general_info($arr_single_record,$_SESSION['recordtype'],true,$p_petition_link,$p_rate_of_progress_link,$p_document_link,$p_idea_link,$p_sign_link,$p_approve_link,$p_licensing_link,$v_url_view_update_record_status); ?></td>
	</tr>
	<tr>
		<td colspan="6" ><hr color="#66CCFF" size="1"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo _CONST_WORK_DATE_LABEL?></td>
		<td>
			<input class="normal_date_textbox" name="txt_work_date" type="text" value="<?php echo $v_work_date; ?>" optional="true" isdate="true" message="<?php echo _CONST_WORK_DATE_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)" readonly>
			<!-- img src="<?php echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" border="0" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH;?>isa-calendar/',document.forms(0).txt_work_date);" style="cursor:hand" -->
		</td>
	</tr><?php 	
	if (onegate_is_tranfer_to_senior_for_recordtype($v_staff_id,$v_recordtype_filter,$_SESSION["recordtype"])) {?>
	<tr class="normal_label">
		<td height="37"></td>
		<td><input type="radio" name="rad_status" value="CHUYEN_HOSO_CQTQ" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms(0).hdn_work)"><?php echo $arr_result_label[7]; $v_dem++; ?> </td>
	</tr><?php 
	}
		$current_status = $arr_single_record["C_DETAIL_STATUS"];
		$p_arr_all_recordtype = $_SESSION["recordtype"];				
		if ($v_recordtype_filter !=""){
			for($i=0; $i< sizeof($p_arr_all_recordtype); $i++){
				if ($p_arr_all_recordtype[$i]['PK_RECORDTYPE'] == $v_recordtype_filter ){
					$v_handle_leader_first_time_list = $p_arr_all_recordtype[$i]['FK_HANDLE_LEADER_FIRST_TIME'];
					$v_arr_handle_leader_first_time_list = explode(",", $v_handle_leader_first_time_list);
					$v_handle_leader_list = $p_arr_all_recordtype[$i]['FK_HANDLE_LEADER'];
					$v_arr_handle_leader_list = explode(",", $v_handle_leader_list);
					$v_approve_leader_list = $p_arr_all_recordtype[$i]['FK_APPROVE_LEADER_LIST'];
					$v_arr_approve_leader_list = explode(",", $v_approve_leader_list);
					//vunh them vao lay danh sach phong ban khong cho phep can bo cung cap trinh ky cho nhau
					$v_array_unit_config = explode(",", NOT_APPROVE_FOR_SAME_POSITION);
					if (in_array(_get_item_attr_by_id($_SESSION['arr_all_staff'], $_SESSION['staff_id'], 'unit_id'), $v_array_unit_config)) {
						$v_arr_handle_leader_list_temp = $v_arr_handle_leader_list;
						$v_arr_handle_leader_list = array();
						for ($i = 0; $i < sizeof($v_arr_handle_leader_list_temp); $i++) {
							if (_get_item_attr_by_id($_SESSION['arr_all_staff'], $_SESSION['staff_id'], 'unit_id') != _get_item_attr_by_id($_SESSION['arr_all_staff'], $v_arr_handle_leader_list_temp[$i], 'unit_id') || $_SESSION['staff_id'] == $v_arr_handle_leader_list_temp[$i]) {
								$v_arr_handle_leader_list[] = $v_arr_handle_leader_list_temp[$i];
							}
						}										
						$v_arr_approve_leader_list_temp = $v_arr_approve_leader_list;
						$v_arr_approve_leader_list = array();
						for ($i = 0; $i < sizeof($v_arr_approve_leader_list_temp); $i++) {
							//echo _get_item_attr_by_id($_SESSION['arr_all_staff'], $_SESSION['staff_id'], 'unit_id')."?"._get_item_attr_by_id($_SESSION['arr_all_staff'], $v_arr_approve_leader_list_temp[$i], 'unit_id')."</br>";
							if (_get_item_attr_by_id($_SESSION['arr_all_staff'], $_SESSION['staff_id'], 'unit_id') != _get_item_attr_by_id($_SESSION['arr_all_staff'], $v_arr_approve_leader_list_temp[$i], 'unit_id')) {								
								$v_arr_approve_leader_list[] = $v_arr_approve_leader_list_temp[$i];
							}
						}					
					}
					//end vunh them vao lay danh sach phong ban khong cho phep can bo cung cap trinh ky cho nhau	
					//echo $i;
					//var_dump($v_handle_leader_list);exit;
					break;
				}
			}
		}				
		$sz_arr_handle_leader_first_time_list = sizeof($v_arr_handle_leader_first_time_list);
		$sz_arr_handle_leader_list = sizeof($v_arr_handle_leader_list);
		$sz_arr_approve_leader_list = sizeof($v_arr_approve_leader_list);
		$is_handle_leader_first_time = in_array($v_staff_id, $v_arr_handle_leader_first_time_list);
		$is_handle_leader = in_array($v_staff_id, $v_arr_handle_leader_list);
		//var_dump($is_handle_leader);
		//echo $v_staff_id;
		$is_approve_leader = in_array($v_staff_id, $v_arr_approve_leader_list);
		?>
		<tr class="normal_label">		
					<td class="normal_label"><?php echo "K&#7871;t qu&#7843; gi&#7843;i quy&#7871;t";?>  </td>
					<td>
					 <table>
					<?php
					//nieuvv--111108--hien thi radio tuong ung voi cong viec dac biet								
						for($j = 0 ; $j < $v_cout; $j ++)
						{
							for($i = 0 ; $i < $v_count_spec_worktype ; $i ++)
							{											
								if($arr_all_spec_worktype[$i]['C_UPDATE_METHOD_START'] == 'PROCESS_RESULT_UPDATE'&& $arr_all_spec_worktype[$i]['FK_WORKTYPE_START'] == $arr_list[$j][0])
								{
									$v_name_spec_worktype = _getname($arr_list,$arr_all_spec_worktype[$i]['FK_WORKTYPE_START']);
								?>
								<tr class="normal_label">						
								<td><input type="radio" name="rad_status" value="<?php echo $arr_all_spec_worktype[$i]['PK_SPEC_WORKTYPE'].",".$arr_all_spec_worktype[$i]['FK_WORKTYPE_START'].",SPEC"; ?>" onclick="refuse_onclick(this,document.forms[0].hdn_work);" optional="true"><?php echo $v_name_spec_worktype;$v_dem++?></td>
							</tr>	
								<?php 
								}
							}
						}
						// the-end-nieuvv-111108---
					if ($current_status == "23"|| $current_status == "34"){?>
                         <?php 
							for ($i = 0; $i < $sz_arr_handle_leader_list; $i++) {
								if ($_SESSION['staff_id'] != $v_arr_handle_leader_list[$i]&& !in_array($v_arr_handle_leader_list[$i],$v_arr_handle_leader_first_time_list)) {
									$v_leader_name = "<b><font color='#0099FF'>" . _get_item_attr_by_id($_SESSION['arr_all_staff'], $v_arr_handle_leader_list[$i], 'name') . "</font></b>";
						?>
                        <tr class="normal_label">
                          <td height="37"><input type="radio" name="rad_status" value="<?php echo 'TRINH_LD_PHONG_DUYET_LAN_HAI,'.$v_arr_handle_leader_list[$i]; ?>" onclick="refuse_onclick(this,document.forms[0].hdn_work);" optional="true" />
                              <?php echo CONST_LEADER_TITLE."&nbsp;".$v_leader_name; $v_dem++; ?> </td>
                        </tr>
                        	<?php }
						  	} 
					//if(!$is_handle_leader){?>
                       <!-- <tr class="normal_label">
                           	<td height="37"><input type="radio" name="rad_status" value="LD_PHONG_TRALAI" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)" />
                              <?php echo CONST_APPROVING_MOVE_BACK_LABEL; $v_dem++;// if($v_num!='') $v_num = $v_num.','.$v_dem; else $v_num = $v_dem;?>		</td>
                        </tr>-->
                <?php //}
				// DatCQ Tra ho so theo yeu cau cua cong dan
						$v_arr_format = explode(",",PB_RUT_HO_SO);
						$arr_staff = $_SESSION['arr_all_staff'];		$arr_unit = $_SESSION['arr_all_unit'];
						$v_unit_name = '';
						
						for($i =0; $i<sizeof($arr_staff); $i++){
							if($v_staff_id == $arr_staff[$i]['id']){
								foreach ($arr_unit as $v_unit)	
								if($arr_staff[$i]['unit_id'] == $v_unit['id']){
									$v_unit_name = $v_unit['code'];
									break;
								}
							}
						}
						
						if(in_array($v_unit_name,$v_arr_format)){ ?>
							
							<tr class="normal_label">
							  <td height="37"><input type="radio" name="rad_status" value="RUT_HO_SO" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_REVOKE_RECORD_MESSAGE_APPROVING?>" onclick="refuse_onclick(this,document.forms[0].hdn_work); "><?php echo CONST_APPROVING_REVOKE_RECORD_LABEL; $v_dem++;?></td>
							</tr>
							
						<?php	}
						// End Tra ho so theo yeu cau cua cong dan
					?>				
                      </table>
                      <?php }
			if ($is_handle_leader) {
		?>
                      <table>
                        <?php 
							for ($i = 0; $i < $sz_arr_approve_leader_list; $i++) { 
								if ($_SESSION['staff_id'] != $v_arr_approve_leader_list[$i] && !in_array($v_arr_approve_leader_list[$i],$v_arr_handle_leader_list)) { 
									$v_leader_name = "<b><font color='#0099FF'>" . _get_item_attr_by_id($_SESSION['arr_all_staff'], $v_arr_approve_leader_list[$i], 'name') . "</font></b>";
						?>
                        <tr class="normal_label">
                          <td height="37"><input type="radio" name="rad_status" value="<?php echo 'TRINH_LD_COQUAN,'.$v_arr_approve_leader_list[$i]; ?>" onclick="refuse_onclick(this,document.forms[0].hdn_work);"         optional="true" />
                              <?php echo CONST_LEADER_TITLE."&nbsp;".$v_leader_name; $v_dem++; ?></td>
                        </tr>
                        <?php }
						  } ?>
						 <!-- Leav_03112008_begin
                        <tr class="normal_label">
                          <td height="37"><input type="radio" name="rad_status" value="LD_PHONG_TRALAI" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)" />
                              <?php echo CONST_APPROVING_MOVE_BACK_LABEL; $v_dem++;// if($v_num!='') $v_num = $v_num.','.$v_dem; else $v_num = $v_dem;?></td>
                        </tr>
						end_03112008_leav-->
                      </table>
                      <?php }if ($is_approve_leader) { ?>
                      <table>
                        <tr class="normal_label">
                          <td height="37"><input type="radio" name="rad_status" value="LD_COQUAN_CAPPHEP" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)" />
                              <?php echo CONST_APPROVING_OK_LABEL;$v_dem++;?></td>
                        </tr>
						<!-- nieuvv--221008--cho phep tra ve thu ly -->
							<!--<tr class="normal_label">
							  <td height="37"><input type="radio" name="rad_status" value="LD_PHONG_TRALAI" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)"><?php echo CONST_APPROVING_MOVE_BACK_LABEL; $v_dem++;// if($v_num!='') $v_num = $v_num.','.$v_dem; else $v_num = $v_dem;?></td>
							</tr>-->
							<!-- the-end-nieuvv-221008----- -->
                        <tr class="normal_label">
                          <td height="37"><input type="radio" name="rad_status" value="LD_COQUAN_TUCHOI" optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)" />
                              <?php echo CONST_APPROVING_NOT_OK_LABEL;$v_dem++; if($v_num!='') $v_num = $v_num.','.$v_dem; else $v_num = $v_dem;?></td>
                        </tr>
                      </table>
                      <?php }?>
					<!--nieuvv--191108--radio tra ve tiep tuc thu ly-->
					<table>
						<tr class="normal_label">
							<td height="37"><input type="radio" name="rad_status"
									   value="<?php echo 'LD_PHONG_TRALAI';?>" 
									   optional="<?php echo CONST_RECORD_STATUS_UPDATE_OPTIONAL?>" message="<?php echo CONST_RECORD_STATUS_UPDATE_MESSAGE?>" onclick="refuse_onclick(this,document.forms[0].hdn_work)"><?php echo CONST_APPROVING_MOVE_BACK_LABEL; $v_dem++;// if($v_num!='') $v_num = $v_num.','.$v_dem; else $v_num = $v_dem;?>
							</td>
						</tr>
					</table>
				<!--nieuvv--191108----->
			
			</td>
	</tr>
		<tr id="tr_reason" class="normal_label" style="display:none">
		<td height="37"><?php echo CONST_RECORD_REASON_LABEL; ?></td>
		<td><textarea name="txt_reason" class="normal_textarea" value="" row="4" style="width:100%" optional="true" message=""></textarea></td>
	</tr>
	<tr>
		<td id="td_reason_revoke" style="display:none" height="37"></td>
		<td id="td_reason" style="display:block" height="37"></td> 
	</tr>
</table>
<table width="100%" >
	<tr>
	<td align="center" width="100%" height="40" valign="bottom"><?php
			if ($is_handle_leader_first_time 
			|| $is_handle_leader
			|| $is_approve_leader
			){
			$v_url_onclick="if(test_status_update(document.forms(0).rad_status,document.forms(0).txt_reason,'".$v_num."')){save_info('UPDATE_RECORD_STATUS');}";
			//$v_url_onclick="save_info('UPDATE_RECORD_STATUS');";?>
				<input type="button" name="btn_save" class="normal_button" value="<?php  echo _CONST_SAVE_BUTTON;?>" onClick="if(check_worktype()){this.disabled=true;}<?php echo $v_url_onclick;?>" onKeyDown="change_focus(document.forms(0),this);" ><?
			}?>				
			<input type="button" name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('DISPLAY_ALL_RECORD_FOR_APPROVING')" onKeyDown="change_focus(document.forms(0),this)">	
	  </td>
	</tr>
</table>
</div>
</form>	
<script language="JavaScript">
	set_focus(document.forms(0));
</script>

